import client from "../utils/pool.mjs"
import dataSource from './brand.json' assert { type: 'json' };
async function importAndCleanData(dataSource) {
    try {
        const dataToImport = dataSource.data;

        for (const brandData of dataToImport) {
            const existingBrand = await client.brand.findFirst({
                where: {
                    yiche_id: brandData.id,
                },
            });

            if (existingBrand) {
                // 更新现有记录
                await client.brand.update({
                    where: {
                        yiche_id: brandData.id,
                    },
                    data: {
                        name: brandData.name,
                        avatar: brandData.logoUrl,
                        all_spell: brandData.allSpell,
                        sale_status: brandData.saleStatus,
                        initial: brandData.initial,
                    },
                });
            } else {
                // 插入新记录
                await client.brand.create({
                    data: {
                        yiche_id: brandData.id,
                        name: brandData.name,
                        avatar: brandData.logoUrl,
                        all_spell: brandData.allSpell,
                        sale_status: brandData.saleStatus,
                        initial: brandData.initial,
                    },
                });
            }
        }

        console.log('Data imported successfully.');
    } catch (error) {
        console.error('Error importing data:', error);
    }
}

// 使用
importAndCleanData(dataSource);
